var t = require;
var e = module;
var o = exports;
Object.defineProperty(o, "__esModule", {value: !0});
o.AdViewEm = void 0;
var a,
    i,
    n = t("AdView"),
    r = t("UIManager"),
    s = t("UIConfig");
(function (t) {
    t[(t.banner = 1)] = "banner";
    t[(t.rewardVedio = 2)] = "rewardVedio";
    t[(t.interstitial = 3)] = "interstitial";
    t[(t.native = 4)] = "native";
    t[(t.custom = 5)] = "custom";
    t[(t.portal = 6)] = "portal";
})((a = o.AdViewEm || (o.AdViewEm = {})));
(function (t) {
    t[(t.receive = 0)] = "receive";
})(i || (i = {}));
var c = (function () {
    function t() {
        this.curAdCache = {};
        this.isViewAding = {};
        this.viewAdCount = {};
        this.adWait = {};
        this.haveLastTime = {};
        this.adSuccess = {};
        this.adObj = {};
        this.onceCallBack = {};
        this.devId = "";
        this.idObj = {};
        this.rewardAd = null;
        this.customAd = null;
        this.firstCustomAd = !1;
        this.lastCustomTime = 0;
        this.customConfig = null;
        this.portalAd = null;
        this.firstPortalAd = !1;
        this.lastPortalTime = 0;
        this.lastTime = 0;
        this.firstReceiveAd = !1;
        this.lastInitCustomTime = 0;
    }
    t.prototype.getAdData = function (t, e, o, i, r, s) {
        var c = this;
        console.log(" ----------------- 当前广告模式vivo");
        this.haveLastTime[a.interstitial] = Date.now();
        var p = this;
        this.getReceive = function (t) {
            console.log("AdViewAndroid -------------stalkooo------ 激励视频回调" + t);
            p.rewardCallBack(t);
        };
        this.loadReceive = function (t) {
            c.adSuccess[a.rewardVedio] = t;
        };
        this.callDevId = function (t) {
            if ("" != t) {
                c.devId = t;
                n.default.devId = c.devId;
            }
        };
        cc.AndroidAdverting = this;
        this.idObj[a.banner] = t;
        this.idObj[a.rewardVedio] = e;
        this.idObj[a.interstitial] = o;
        this.idObj[a.native] = i;
        this.idObj[a.custom] = r;
        this.idObj[a.portal] = s;
        this.curAdCache[a.banner] = {
            show: this.showBannerAd.bind(this),
            hide: this.hideBannerAd.bind(this),
            preLoad: this.preLoadBannerAd.bind(this),
            destory: this.destoryBannerAd.bind(this),
            isCanPlay: this.canPlayAd.bind(this)
        };
        this.curAdCache[a.rewardVedio] = {
            show: this.showRewarVediodAd.bind(this),
            hide: this.hideRewarVediodAd.bind(this),
            preLoad: this.preLoadRewarVediodAd.bind(this),
            destory: this.destoryRewarVediodAd.bind(this),
            isCanPlay: this.canPlayReward.bind(this)
        };
        this.curAdCache[a.interstitial] = {
            show: this.showInterstitial.bind(this),
            hide: this.hideInterstitial.bind(this),
            preLoad: this.preLoadInterstitial.bind(this),
            destory: this.destoryInterstitial.bind(this),
            isCanPlay: this.canPlayAd.bind(this)
        };
        this.curAdCache[a.custom] = {
            show: this.showCustomAd.bind(this),
            hide: this.hideCustomAd.bind(this),
            preLoad: this.preLoadCustomAd.bind(this),
            destory: this.destroyCustomAd.bind(this),
            isCanPlay: this.canPlayAd.bind(this)
        };
        this.curAdCache[a.portal] = {
            show: this.showPortalAd.bind(this),
            preLoad: this.preLoadPortalAd.bind(this),
            destory: this.destroyPortalAd.bind(this),
            isCanPlay: this.canPlayAd.bind(this)
        };
        setTimeout(function () {
            c.idObj[a.rewardVedio] && c.preLoadRewarVediodAd();
            c.idObj[a.portal] && c.preLoadPortalAd();
        }, 5e3);
        return this.curAdCache;
    };
    t.prototype.rewardCallBack = function (t) {
        this.onceCallBack[a.rewardVedio] && this.onceCallBack[a.rewardVedio] && this.onceCallBack[a.rewardVedio](t);
        this.onceCallBack[a.rewardVedio] = null;
    };
    t.prototype.canPlayReward = function () {
        return !!this.adSuccess[a.rewardVedio];
    };
    t.prototype.canPlayAd = function () {
        return !0;
    };
    t.prototype.showBannerAd = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.doShowBanner = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.showRewarVediodAd = function (t) {
        void 0 === t && (t = null);
        console.log("开始播放激励视频");
        this.onceCallBack[a.rewardVedio] = t;
        if (null != this.rewardAd && this.adSuccess[a.rewardVedio])
            this.rewardAd
                .show()
                .then(function () {
                    console.log("激励视频广告开始播放");
                })
                .catch(function (t) {
                    console.log("激励视频广告播放失败", JSON.stringify(t));
                });
        else {
            console.log("暂时没有广告了");
            this.initRewardedAd();
            this.rewardCallBack && this.rewardCallBack(!1);
        }
        this.viewAdCount[a.rewardVedio] = this.getObjCount(this.viewAdCount, a.rewardVedio) + 1;
    };
    t.prototype.showInterstitial = function (t) {
        void 0 === t && (t = null);
        return !0;
    };
    t.prototype.hideBannerAd = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.hideRewarVediodAd = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.hideInterstitial = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.preLoadBannerAd = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.getObjCount = function (t, e) {
        return t[e] ? t[e] : 0;
    };
    t.prototype.preLoadRewarVediodAd = function (t) {
        void 0 === t && (t = null);
        console.log("预加载激励");
        if (Date.now() - this.lastTime > 5e3) {
            this.lastTime = Date.now();
            this.firstReceiveAd = !0;
            this.initRewardedAd();
        }
    };
    t.prototype.preLoadInterstitial = function (t) {
        void 0 === t && (t = null);
    };
    t.prototype.destoryBannerAd = function () {};
    t.prototype.destoryRewarVediodAd = function () {};
    t.prototype.destoryInterstitial = function () {};
    t.prototype.viewData = function (t, e) {
        console.log("QTtAdDo ----------------- " + t, e);
    };
    t.prototype.setCustomConfig = function (t) {
        this.customConfig = t;
    };
    t.prototype.preLoadCustomAd = function () {
        if (Date.now() - this.lastCustomTime > 5e3) {
            this.lastCustomTime = Date.now();
            this.firstCustomAd = !0;
            console.log("创建一个原生模板广告");
            this.initCustomAd();
        }
    };
    t.prototype.destroyCustomAd = function () {
        null != this.customAd && this.customAd.destroy();
    };
    t.prototype.showCustomAd = function () {
        var t = this;
        if (null == this.customAd || this.customAdIsShow()) {
            console.log("没广告可以展示，先创建");
            this.initCustomAd();
        } else
            this.customAdIsShow()
                ? console.log("广告正在展示")
                : this.customAd
                      .show()
                      .then(function () {
                          console.log(t.idObj[a.custom], "show success");
                      })
                      .catch(function (e) {
                          console.log(t.idObj[a.custom], "show fail with:" + e.errCode + "," + e.errMsg);
                      });
    };
    t.prototype.hideCustomAd = function () {
        if (null != this.customAd) {
            this.customAd.hide();
            r.default.closeUiByUIID(s.UIID.AdViewCom);
        }
    };
    t.prototype.initRewardedAd = function () {
        var t = this;
        console.log(this.idObj[a.rewardVedio]);
        if (this.idObj[a.rewardVedio]) {
            console.log("创建vivo激励视频广告");
            this.rewardAd = n.default.Plat.createRewardedVideoAd({posId: this.idObj[a.rewardVedio]});
            this.rewardAd.onError(function (e) {
                console.log("激励视频广告加载失败", e);
                t.adSuccess[a.rewardVedio] = !1;
                t.rewardCallBack(!1);
            });
            this.rewardAd.onLoad(function (e) {
                console.log("激励视频广告加载完成-onload触发", JSON.stringify(e));
                t.adSuccess[a.rewardVedio] = !0;
            });
            this.rewardAd.onClose(function (e) {
                console.log("视频广告关闭回调");
                if (e && e.isEnded) {
                    console.log("正常播放结束，可以下发游戏奖励");
                    t.rewardCallBack(!0);
                } else {
                    console.log("播放中途退出，不下发游戏奖励");
                    t.rewardCallBack(!1);
                }
                t.adSuccess[a.rewardVedio] = !1;
            });
        } else console.log("视频广告参数没有配置");
    };
    t.prototype.initCustomAd = function () {
        var t = this;
        if (Date.now() - this.lastInitCustomTime < 5e3) console.log("原生模板创建时间相隔太近");
        else {
            this.lastInitCustomTime = Date.now();
            if (this.idObj[a.custom]) {
                if (this.customAd) {
                    this.customAd.destroy();
                    this.customAd = null;
                }
                null == this.customConfig && (this.customConfig = {top: 500, left: 0});
                console.log("创建的原生广告模板id", this.idObj[a.custom]);
                this.customAd = n.default.Plat.createCustomAd({posId: this.idObj[a.custom], style: this.customConfig});
                this.customAd.onLoad(function () {
                    t.adSuccess[a.custom] = !0;
                    console.log("[原生模板广告] 广告加载成功");
                });
                this.customAd.onError(function (e) {
                    console.log("错误监听：", t.idObj[a.custom], JSON.stringify(e));
                    t.customAd.destroy();
                    r.default.closeUiByUIID(s.UIID.AdViewCom);
                });
                this.customAd.onHide(function () {
                    n.default.isCloseCustomAd = !0;
                    n.default.lastClickTime = Date.now();
                    console.log("customAd广告隐藏");
                });
                this.customAd.onClose(function () {
                    n.default.isCloseCustomAd = !0;
                    t.customAd.destroy();
                    t.initCustomAd();
                    console.log("模板广告被关闭");
                    r.default.closeUiByUIID(s.UIID.AdViewCom);
                });
            } else console.log("原生模板广告参数没有配置");
        }
    };
    t.prototype.customAdIsShow = function () {
        return !!this.customAd && this.customAd.isShow();
    };
    t.prototype.preLoadPortalAd = function () {
        if (Date.now() - this.lastPortalTime > 5e3) {
            this.lastPortalTime = Date.now();
            this.firstPortalAd = !0;
            console.log("创建一个九宫广告");
            this.createNewPortalAd();
        }
    };
    t.prototype.destroyPortalAd = function () {
        null != this.portalAd && this.portalAd.destroy();
    };
    t.prototype.showPortalAd = function () {};
    t.prototype.createNewPortalAd = function () {
        var t = this;
        if (this.idObj[a.portal]) {
            if (this.portalAd) {
                this.portalAd.destroy();
                this.portalAd = null;
            }
            if (n.default.Plat.getSystemInfoSync().platformVersionCode < 1076) console.log("平台版本国小，无法创建");
            else {
                console.log("创建的九宫广告id", this.idObj[a.portal]);
                this.portalAd = n.default.Plat.createBoxPortalAd({
                    posId: this.idObj[a.portal],
                    image: "https://res1.yonyow.com/CatRestaurant/vivo/gdjc.png",
                    marginTop: 200
                });
                this.portalAd.onLoad(function () {
                    t.adSuccess[a.portal] = !0;
                    console.log("[九宫广告] 广告加载成功");
                });
                this.portalAd.onError(function (e) {
                    console.log("九宫广告加载错误监听：", t.idObj[a.portal], JSON.stringify(e));
                });
                this.portalAd.onClose(function () {
                    console.log("互推盒子九宫格广告关闭");
                });
                this.portalAd.onShow(function (t) {
                    console.log(t);
                });
                this.portalAd
                    .show()
                    .then(function () {
                        console.log(t.idObj[a.portal], "show success");
                    })
                    .catch(function (e) {
                        console.log(t.idObj[a.portal], "show fail with:" + e.errCode + "," + e.errMsg);
                    });
            }
        } else console.log("九宫广告参数没有配置");
    };
    t.prototype.closeBoxPortalAd = function () {
        if (null != this.portalAd) {
            this.portalAd.isDestroyed = !0;
            this.portalAd.destroy();
        }
    };
    t.prototype.hidePortalAd = function () {
        null != this.portalAd && this.portalAd.hide();
    };
    return t;
})();
o.default = c;
